package com.alumni_circle.core.web.rbac;

import com.alumni_circle.core.config.SysLog;
import com.alumni_circle.core.entity.ResponseModel;
import com.alumni_circle.core.entity.rbac.RoleAuthority;
import com.alumni_circle.core.entity.rbac.UserRole;
import com.alumni_circle.core.entity.rbac.VO.RoleAuthorityUpdateVO;
import com.alumni_circle.core.service.rbac.impl.RoleAuthorityServiceImpl;
import com.alumni_circle.core.utils.ModelUtils;
import com.alumni_circle.core.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author 龙小虬
 * @since 2020-08-02 20:43
 */
@Api(tags = "用户角色管理")
@Controller
@RequestMapping("/userAuthority")
public class UserAuthorityController extends BaseController<UserRole> {

    @Resource
    RoleAuthorityServiceImpl roleAuthorityService;


    /**
     * 更新用户角色信息
     * @param roleAuthorityUpdateVO
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/updateUserAuthority", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "更新用户角色信息", notes = "更新用户角色信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="改",accessInfo="更新用户角色信息",url="/userAuthority/updateUserAuthority")
    public ResponseModel addUserAuthority(@ApiParam(required = true, name = "userRoleUpdateVO")
                                 @RequestBody RoleAuthorityUpdateVO roleAuthorityUpdateVO) {


       return new ResponseModel<>(roleAuthorityService.updateById(ModelUtils.transform(roleAuthorityUpdateVO, RoleAuthority.class)));
    }

}
